/**
 * @file 文章model
 * @author wangshaozhi(wangshaozhi@baidu.com)
 */

import {action, makeObservable, observable} from "mobx";

class Article implements Article.IArticleProps {
    id: string = '';
    title: string = '';
    content: string = '';
    introduction: string = '';
    publishTime: string = '';
    type: Article.EArticleType = Article.EArticleType.STUDY_NOTES;
    viewsCount: number = 0;
    isDel: Article.EDel = Article.EDel.NOT_DELETE;
    isSaved: Article.ESaved = Article.ESaved.NOT_SAVED;
    isPublish: Article.EPublish =  Article.EPublish.NOT_PUBLISH;
    cover: string = 'https://p1.qhimg.com/bdr/__85/t011917e5b14e3cd8e8.jpg';

    constructor(props: Partial<Article.IArticleProps>) {
        makeObservable(this, {
            id: observable,
            title: observable,
            content: observable,
            introduction: observable,
            publishTime: observable,
            type: observable,
            viewsCount: observable,
            isDel: observable,
            isPublish: observable,
            cover: observable,
            isSaved: observable
        });
        this.update(props);
    }

    update = action((data: Partial<Article.IArticleProps>) => {
        Object.assign(this, data);
    })
}

namespace Article {
    export interface IArticleProps {
        /** 文章id */
        id: string;
        /** 文章标题 */
        title: string;
        /** 文章内容 */
        content: string;
        /** 文章简介 */
        introduction: string;
        /** 文章发布时间 */
        publishTime: string;
        /** 文章类型 */
        type: EArticleType;
        /** 阅读人数 */
        viewsCount: number;
        /** 是否删除 */
        isDel: EDel;
        /** 是否发布了 */
        isPublish: EPublish;
        /** 文章封面 */
        cover: string;
        /** 是否保存了 */
        isSaved: ESaved;
    }
    export enum EArticleType {
        /** 学习笔记 */
        STUDY_NOTES = 1,
    
        /** 个人相关 */
        PERSONAL = 2
    }
    export enum EDel {
        /** 没有删除 */
        NOT_DELETE,
        /** 删除了 */
        DELETED
    }
    export enum EPublish {
        /** 没有发布 */
        NOT_PUBLISH,
        /** 发布了 */
        PUBLISHED
    }
    export enum ESaved {
        /** 没有保存 */
        NOT_SAVED,
        /** 保存了 */
        SAVED
    }
}

export default Article;